﻿<?php 
require_once(dirname(__FILE__)."/../../libs/login/login.php");
require_once(dirname(__FILE__)."/../../libs/dbclass/dbconnect.php");
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../../admin/libs/article_class.php");
require_once(dirname(__FILE__)."/../../admin/libs/shuxing_class.php");
require_once(dirname(__FILE__)."/../../admin/libs/config_class.php");
$lg=new login();
$lg->checklogin("admin_member");//检验是否登录
$mc=new libstr();
$cf=new config();
$ar=new article();
$sx=new shuxing();

//获取文章性质
$tuijie=$cf->getmarks($type);
//获得属性
$nianjis=$sx->getshuxinglist("nianji_class");
$xuekes=$sx->getshuxinglist("xueke_class");
//上传文章
if($mc->Ismp($_POST['addbtn'])!="")
{
$topicname=$mc->request("topicname","");
if($topicname==""){$mc->msg("文章名称不能为空！");}
$author=$mc->request("author","");
$codeid=$mc->request("codeid",0);
$cataid=$mc->request("cataid","");
if($cataid==""){$mc->msg("请选择文章类别！");}
if($ar->myck($cataid)=='true'){$mc->msg("文章类别存在子类，请选择此类别的最底层子类作类别！");}
$tuijie="";
if(count($_POST['tuijie'])>0){
$tuijie=sprintf("%s",implode("|", $_POST['tuijie']));//属性多选(考虑优化，目前为like查找多属性的)	
}
//exit($tuijie);
$content=$mc->request("content","");
$biaoqian=$mc->request("biaoqian","");
$keyword=$mc->request("keyword","");
$pic=$mc->request("pic","");
$durl=$mc->request("durl","");
$daxiao=$mc->request("daxiao",0);
$isshow=1;
$adduserno=0;

$ar->article_add($topicname,$codeid,$author,$cataid,$tuijie,$content,$biaoqian,$keyword,$pic,$durl,$daxiao,$adduserno,$isshow);
$mc->msg("数据成功保存","article_list.php?classid=".$_POST["cataid"]);//成功返回列表页
}
$path="文章添加";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>上传文章</title>
<link rel="stylesheet" type="text/css" href="../../plug/swfupload/uploadify.css">
	<link href="../css/css.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="../../plug/kindeditor/themes/default/default.css" />
	<!--文章图片css!-->
	<style>
.imgall{position: relative; width:100px; height:100px; float:left; margin-right:10px}

.imgall img{  }
.imgall span{ position:absolute; width:100px; height:32px;bottom:0px; display:none; }
.imgall:hover span{display:block;}
.imgall span input{float:right; cursor:pointer; background-image: url(../images/trash-alt-empty-32.png); width:32px; height:32px; border:0; }
</style>
	<script type="text/javascript" src="../js/jquery.js"></script>
	<script charset="utf-8" src="../../plug/kindeditor/kindeditor-min.js"></script>
	<script charset="utf-8" src="../../plug/kindeditor/lang/zh_CN.js"></script>
    <script type="text/javascript" src="../../plug/swfupload/jquery.min.js"></script>
    <script type="text/javascript" src="../../plug/swfupload/jquery.uploadify-3.1.min.js"></script>
    <script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true
				});
				
			});
		</script>

	<script type="text/javascript">
	  //图片上传
	$(document).ready(function() {
        $('#file_upload').uploadify({
            'onSelect' :function(){shows3();},
			'onUploadSuccess' : function(file, data, response) {  
 		     // alert(data);
			  var board=document.getElementById("pic0");

			  
			  if(board.value!='')
			  {
			  	  $("#allpics").append("<div class='imgall'><img src='"+data+"' width='100' height='100' /><span><input type='button' title='删除'></span></div>");
				  board.value=board.value+','+data;
			  }else
			  {
			  	 $("#allpics").html("<div class='imgall'><img src='"+data+"' width='100' height='100' /><span><input type='button' title='删除'></span></div>");
			      board.value=data;
			  }
			  
//成功后加载	删除修改图片代码		  
	$(".imgall input").each(function(i){
		$(this).click(function(){
			$(this).parent().parent().remove();
			var im="";
			$(".imgall").each(function(index){
				
				if(im==""){
					im=$(".imgall img:eq("+index+")").attr('src');
					}else{
					im+=","+$(".imgall img:eq("+index+")").attr('src');	
						}
				})
			  board.value=im;
			  if(im==""){
			  	 $("#allpics").html('<img src="../../plug/swfupload/moren.jpg" width="100px" height="100px" >');//如果为空，显示默认的图片
			  }
			})
		
		})
    
			  
            }, 	
			

		    'onUploadStart' : function(file) {
            $("#file_upload").uploadify("settings","formData",{"pic1":$("#aaa").val()});
    		},	
    		
			'removeTimeout':'4',//进度条消失时间
			'method'   : 'post',
			'buttonImage':'','height': '30',
			'width': '75',
			'queueID' : 'some_file_queue',
			'displayData'    : 'percentage',
			'fileTypeExts'     : '*.jpg;*.jpeg;*.png;*.gif;*.bmp',
	        'fileTypeDesc'    : '支持的格式(.JPG,.JPEG,.PNG,.GIF,.BMP)',//允许的格式
			'fileSizeLimit':'100024KB',//上传文件大小限制
			'queueSizeLimit':'10',//同时上传的文件最大数
			//'auto':false,//是否选取文件后自动上传
            'swf' : '../../plug/swfupload/uploadify.swf?ver='+ Math.random(),//是组件自带的flash，用于打开选取本地文件的按钮 
            'uploader' : '../../plug/swfupload/poster.php?type=2',
            'buttonText': '上传图片'
			 
			 
            // Your options here
        });
		

    });	
	//$('#file_upload').uploadify('upload','*')//控制文件上传		
</script>



  <script type="text/javascript">
  //判断是否为底层类
  function ischild(id){
  	$.ajax({ 
        type: "POST", 
        url: "../ajax/inc.php", 
        dataType: "text", 
        data: {"isbtn":true,"id":id}, 
 success: function(data){
 	  if(data.indexOf("have child")!=-1)
  {
  	 alert("该类别存在子类，请选择此类别的最底层子类作类别");
	  return ;
  }
 }
  	})
  	
  }
  </script>
</head>
<body style="background:#fff"> 
<div class="content">
    <div class="right">
   <form action="" method="POST">
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="100%" height="24" class="top_head">&nbsp;</td>
          </tr>
          <tr>
            <td valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="1%" align="right"  height="45">&nbsp;</td>
                    <td width="99%" >
                     <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="55%" style="padding-left:20px;padding-top:10px;"><img src="../images/head.gif" width="13" height="11"><b><?php echo $path;?></b><a href="article_list.php?classid=<?php echo $_GET["classid"];?>" style=" margin-left:20px; text-decoration:underline;">返回列表</a></td>
                        <td width="45%" align="right">&nbsp;</td>
                      </tr>
                    </table>
                    </td>
                  </tr>
                </table>
            </td>
          </tr>
   </table>
   
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="liebiao">
  <tr>
    <td width="11%" height="40" align="right" valign="middle">文章名称：</td>
    <td height="40" valign="middle">
      <input type="text" name="topicname" id="topicname" /> <font>（*文章名称不能为空）</font></td>
      <input type="hidden" name="codeid" id="codeid" value="<?php echo $ar->setcodeid();?>"/>
    </tr>
 <!-- <tr>
    <td height="40" align="right">文章编号：</td>
    <td height="40"><span><?php echo $ar->setcodeid();?><input type="hidden" name="codeid" id="codeid" value="<?php echo $ar->setcodeid();?>"/>
     </span></td>
    </tr>
  <tr>-->

  <tr>
    <td height="50" align="right" valign="middle">文章作者：</td>
    <td height="50" valign="middle"><span><input type="text" name="author" id="author" /></span></td>
    </tr>
  <tr>
    <td align="right" valign="middle">文章类别：</td>
    <td valign="middle" style="padding-bottom:6px;"><div class="ziyuan">
      <select name="cataid" id="cataid" onchange="ischild(this.value)">
      <option value="">请选择类别</option>
       <?php 
		$db->depth=0;
		$twhere="";  
		$db->getchild("article_class",0,$mc->Ismp($_GET["classid"]),"ID","-",$twhere);
		
		?>
      </select>
    </div></td>
    </tr>
      <tr>
    <td height="30" align="right" valign="middle">文章性质：</td>
    <td height="30" valign="middle"><div class="kejian">
    <?php foreach ($tuijie as $tj){?>
      <input type="checkbox" name="tuijie[]" value="<?php echo $tj["classvalue"]?>" />
      <span><?php echo $tj["classname"]?></span>
    <?php }?>
    </div></td>
    </tr>
  <tr>
    <td height="auto" align="right" valign="top" style="padding-top:8px;">内容介绍：</td>
    <td height="auto" valign="top" style="padding-top:10px;padding-bottom:10px;"><textarea id="content" name="content" style="width:898px;height:415px;visibility:hidden;"></textarea></td>
    </tr>
<!--  <tr>
    <td height="50" align="right" valign="middle">标签：</td>
    <td height="50" valign="middle"><input type="text" name="biaoqian" id="biaoqian" /><font>（多个标签用空格隔开）</font></td>
    </tr>
  <tr>
    <td height="50" align="right" valign="middle">关键词：</td>
    <td height="50" valign="middle"><input type="text" name="keyword" id="keyword" /><font>（多个关键词用空格隔开）</font></td>
   </tr>-->
   <tr style="display:none">
    <td height="50" align="right" valign="middle">添加图片：</td>
    <td height="50" valign="middle"><input type="text" name="pic" id="pic0" /><div class="anniu"><input type="file" name="file_upload" id="file_upload" /></div><font>（可直接复制图片路径，如：http://xx.com/xx.jpg，多张图片用 , 隔开）</font></td><!-- 这里的全屏id有影响!-->
    </tr>
     <tr style="display:none">
    <td height="50" align="right" valign="middle">图片预览：</td>
    <td height="50" valign="middle"><div id="allpics"><img src="../../plug/swfupload/moren.jpg" width='100px' height="100px" ></div></td><!-- 预览的图片!-->
    </tr>
    <!--上传图片弹出对话框，显示上传的进度条!-->
    <div class="xz" id="Idiv3" style="display:none; z-index:100">
		<div class="xzleft"></div>
		<Div class="xzmid">
		  <h2>正在上传图片...</h2>
		  <p>最多上传5张图片，支持jpg,gif,png,jpeg,bmp格式</p>
		  <div id="some_file_queue"></div>
		  <Div class="anu"><input  type="button" onclick="$('#file_uploads3').uploadify('cancel','*');return closeDivs3()"  value="关闭" /></Div>
		</Div>
		<div class="xzright"></div>
		</div>
	</div>	


  <tr style="display:none">
    <td height="50" align="right" valign="middle">上传文件：</td>
    <td height="50" valign="middle"><input type="text" name="durl" id="durl" /><div class="anniu"> <input type="submit" name="button3" id="button3" value="上传文件" /></div></td>
    </tr>

	
  <tr  style="display:none">
    <td height="50" align="right" valign="middle">文件大小：</td>
    <td height="50" valign="middle"><span><input type="text" name="daxiao" id="daxiao" /></span><Font>（以KB为单位,该项不用填）</Font></td>
    </tr>
  <tr>
    <td height="50" align="right" valign="middle">&nbsp;</td>
    <td height="50" valign="middle"><bdo>
      <input type="submit" name="addbtn" id="addbtn" value="提交保存" />
    </bdo></td>
    </tr>
    </table>
    </from>
    </div>
        </div>

</body>
</html>
<script langue="javascript">
function shows3()
{
	
var Idiv=document.getElementById("Idiv3"); 
Idiv.style.display="block";
//以下部分要将弹出层居中显示
Idiv.style.left=(document.documentElement.clientWidth-Idiv.clientWidth)/2+document.documentElement.scrollLeft+"px"; 
Idiv.style.top=(document.documentElement.clientHeight-Idiv.clientHeight)/2+document.documentElement.scrollTop-50+"px";

//以下部分使整个页面至灰不可点击
var procbg = document.createElement("div"); //首先创建一个div
procbg.setAttribute("id","mybg"); //定义该div的id
procbg.style.background ="#000000";
procbg.style.width ="100%";
procbg.style.height ="100%";
procbg.style.position ="fixed";
procbg.style.top ="0";
procbg.style.left ="0";
procbg.style.zIndex ="90";
procbg.style.opacity ="0.6";
procbg.style.filter ="Alpha(opacity=70)";

//以上部分也可以用csstext代替
// procbg.style.cssText="background:#000000;width:100%;height:100%;position:fixed;top:0;left:0;zIndex:500;opacity:0.6;filter:Alpha(opacity=70);";
//背景层加入页面
document.body.appendChild(procbg);
document.body.style.overflow ="hidden"; //取消滚动条


//以下部分实现弹出层的拖拽效果
var posX;
var posY;
Idiv.onmousedown=function(e)
{
if(!e) e = window.event; //IE
posX = e.clientX - parseInt(Idiv.style.left);
posY = e.clientY - parseInt(Idiv.style.top);
document.onmousemove = mousemove; 
}
document.onmouseup =function()
{
document.onmousemove =null;
}
function mousemove(ev)
{
if(ev==null) ev = window.event;//IE
Idiv.style.left = (ev.clientX - posX) +"px";
Idiv.style.top = (ev.clientY - posY) +"px";
}

} 


function closeDivs3() //关闭弹出层
{
var Idiv=document.getElementById("Idiv3"); 
Idiv.style.display="none";
document.getElementById("mybg").style.display="none";
document.body.style.overflow ="auto"; //恢复页面滚动条
procbg=document.getElementById("mybg");
procbg.parentNode.removeChild(procbg);



}

</script>
